package com.stp.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 主题交换机 发布订阅
 */
@Configuration
public class TopicConfig {
    //topic主题模式
    private static final String QUEUE_TOPIC1 = "queue_topic01";
    private static final String QUEUE_TOPIC2 = "queue_topic02";
    private static final String EXCHANGE_TOPIC = "topicExchange";
    //路由
    private static final String routing_key01 = "#.queue.#";
    private static final String routing_key02 = "*.queue.#";


    @Bean
    public Queue queue_topic01() {
        return new Queue(QUEUE_TOPIC1);
    }

    @Bean
    public Queue queue_topic02() {
        return new Queue(QUEUE_TOPIC2);
    }

    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(EXCHANGE_TOPIC);
    }

    @Bean
    public Binding binding_topic1() {
        //将队列queue1和交换机进行绑定
        return BindingBuilder.bind(queue_topic01()).to(topicExchange()).with(routing_key01);
    }

    @Bean
    public Binding binding_topic2() {
        //将队列queue1和交换机进行绑定
        return BindingBuilder.bind(queue_topic02()).to(topicExchange()).with(routing_key02);
    }
}
